﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Permissions;
using System.Web.UI.WebControls.WebParts;
using SharePointOfView.Properties;

namespace SharePointOfView.WebControls
{
    [AttributeUsage(AttributeTargets.Property), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class LocalizedWebDisplayNameAttribute : WebDisplayNameAttribute
    {
        // Fields
        private string _displayName;
        public static new readonly WebDisplayNameAttribute Default = new WebDisplayNameAttribute();

        // Methods
        public LocalizedWebDisplayNameAttribute()
            : this(string.Empty)
        {
        }

        public LocalizedWebDisplayNameAttribute(string displayName)
        {
            this._displayName = Resources.ResourceManager.GetString(displayName);
        }

        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return true;
            }
            WebDisplayNameAttribute attribute = obj as WebDisplayNameAttribute;
            return ((attribute != null) && (attribute.DisplayName == this.DisplayName));
        }

        public override int GetHashCode()
        {
            return this.DisplayName.GetHashCode();
        }

        public override bool IsDefaultAttribute()
        {
            return this.Equals(Default);
        }

        // Properties
        public override string DisplayName
        {
            get
            {
                return this.DisplayNameValue;
            }
        }

        protected new string DisplayNameValue
        {
            get
            {
                return this._displayName;
            }
            set
            {
                this._displayName = value;
            }
        }

    }
}
